home *** CD-ROM | disk | FTP | other *** search
/ CD Loisirs 6 / CDL_N6.iso / mac / CD Loisirs N°6 / PaperPlanes / Paper Planes / Shared.dxr / 01022_FuelGauge.ls < prev    next >
Encoding:
Text File  |  1994-08-25  |  3.2 KB  |  112 lines

  1. property Background, Drag, DragPict, IndicatorField, NLevels, CurrentLevel, levelSize, FullHeight, DragHalfHeight, Base
  2.  
  3. on birth me, backgroundSprite, dragSprite, dragCast, valueField
  4.   set Background to backgroundSprite
  5.   set Drag to dragSprite
  6.   set DragPict to dragCast
  7.   set IndicatorField to valueField
  8.   puppetSprite(Drag, 1)
  9.   set DragHalfHeight to the height of sprite Drag / 2
  10.   set FullHeight to the height of sprite Background - (2 * DragHalfHeight)
  11.   set Base to the locV of sprite Background - DragHalfHeight
  12.   set NLevels to 0
  13.   set CurrentLevel to 0
  14.   set levelSize to float(0)
  15.   set IndicatorField to valueField
  16.   return me
  17. end
  18.  
  19. on mSetNumLevels me, numLevels
  20.   set NLevels to numLevels
  21.   set CurrentLevel to numLevels
  22.   set levelSize to float(FullHeight) / float(NLevels)
  23. end
  24.  
  25. on mUpdateLevelIndicator me, whichLevel
  26.   set the text of field IndicatorField to string(whichLevel)
  27.   updateStage()
  28. end
  29.  
  30. on mSetLevel me, whichLevel
  31.   if (NLevels > 0) and (whichLevel > 0) and (whichLevel <= NLevels) then
  32.     set newHeight to (levelSize * float(whichLevel - 1)) + (levelSize / 2.0)
  33.     set newHeight to integer(newHeight)
  34.     set the locV of sprite Drag to Base - newHeight
  35.     mUpdateLevelIndicator(me, whichLevel)
  36.     set CurrentLevel to whichLevel
  37.   end if
  38. end
  39.  
  40. on mGetCurrentLevel me
  41.   return CurrentLevel
  42. end
  43.  
  44. on mComputeNewLevel me, dragLocation
  45.   set newLevel to float(Base - dragLocation) / levelSize
  46.   set newLevel to integer(newLevel)
  47.   if newLevel < 1 then
  48.     set newLevel to 1
  49.   else
  50.     if newLevel > NLevels then
  51.       set newLevel to NLevels
  52.     end if
  53.   end if
  54.   return newLevel
  55. end
  56.  
  57. on mDragLevel me
  58.   set firstTime to 1
  59.   set offset to the locV of sprite Drag - the mouseV
  60.   repeat while the mouseDown
  61.     if rollOver(Background) or rollOver(Drag) then
  62.       if firstTime then
  63.         set the castNum of sprite Drag to the number of cast DragPict + 1
  64.         updateStage()
  65.         set firstTime to 0
  66.       end if
  67.       set newLoc to the mouseV + offset
  68.       if (newLoc <= Base) and (newLoc >= (Base - FullHeight)) then
  69.         set the locV of sprite Drag to newLoc
  70.         set newLevel to mComputeNewLevel(me, newLoc)
  71.         mUpdateLevelIndicator(me, newLevel)
  72.       else
  73.         if newLoc > Base then
  74.           set the locV of sprite Drag to Base
  75.           set newLevel to mComputeNewLevel(me, Base)
  76.           mUpdateLevelIndicator(me, newLevel)
  77.         else
  78.           if newLoc < (Base - FullHeight) then
  79.             set the locV of sprite Drag to Base - FullHeight
  80.             set newLevel to mComputeNewLevel(me, Base - FullHeight)
  81.             mUpdateLevelIndicator(me, newLevel)
  82.           end if
  83.         end if
  84.       end if
  85.       next repeat
  86.     end if
  87.     if firstTime = 0 then
  88.       set the castNum of sprite Drag to the number of cast DragPict
  89.       updateStage()
  90.       set firstTime to 1
  91.     end if
  92.   end repeat
  93. end
  94.  
  95. on mReleaseDrag me
  96.   set the castNum of sprite Drag to the number of cast DragPict
  97.   updateStage()
  98.   set newLevel to mComputeNewLevel(me, the locV of sprite Drag)
  99.   mSetLevel(me, newLevel)
  100.   return newLevel
  101. end
  102.  
  103. on mRemoveGaugeUI me
  104.   puppetSprite(Drag, 0)
  105.   set the text of field IndicatorField to " "
  106. end
  107.  
  108. on mRestoreGaugeUI me
  109.   puppetSprite(Drag, 1)
  110.   mSetLevel(me, CurrentLevel)
  111. end
  112.